from django.db import models
from tagging.fields import TagField
from blog.managers import PostManager

class Category(models.Model):
    title = models.CharField(max_length = 50)
    slug = models.SlugField(unique = True)

    def __unicode__(self):
        return self.title

class Post(models.Model):
    status_choices = (
        (1, 'public'), 
        (2, 'draft'), 
    )
    title = models.CharField('titiji', max_length = 50)
    slug = models.SlugField(unique = True)
    categories = models.ForeignKey(Category)
    body = models.TextField()
    status = models.IntegerField(choices = status_choices)
    date = models.DateTimeField(auto_now_add = True)
    allow_comment = models.BooleanField(default = True)
    tag = TagField()
    objects = PostManager()

    def __unicode__(self):
        return self.title

    def get_prev_post(self):
        return self.get_previous_by_date(status = 1)

    def get_next_post(self):
        return self.get_next_by_date(status = 1)
